<template>
  <a-button
    @click="onClick"
    :disabled="disabled"
    type="text"
    size="small"
    style="padding: 0"
  >
    复制/转移文件
  </a-button>
</template>
<script setup>
import { ref, computed } from 'vue'
import {
  useRowSelectionActive,
  useRowSelection,
  useDataSource,
  useTreeSelectedInfo,
  useLockForInUse,
  useTransferBarVisible,
} from './provide-context.js'
/**
 * 全局
 */
let dataSource = useDataSource()
let treeSelectedInfo = useTreeSelectedInfo()
let rowSelectionActive = useRowSelectionActive()
let rowSelection = useRowSelection()
let lockForInUse = useLockForInUse()
let transferBarVisible = useTransferBarVisible()
/**
 * 锁标识
 */
let lockSymbol = Symbol('transfer')
/**
 * 事件
 */
function onClick() {
  if (rowSelectionActive.value) {
    lockForInUse.value = null
    delete rowSelection.getCheckboxProps
  } else {
    lockForInUse.value = lockSymbol
    rowSelection.getCheckboxProps = record => ({
      disabled: record.dataType === 'folder' || record.dataStatus === 2,
    })
  }
  transferBarVisible.value = !transferBarVisible.value
  rowSelectionActive.value = !rowSelectionActive.value
  rowSelection.selectedRowKeys.value = []
}
/**
 * 是否在创建中
 */
// let createing = computed(() =>
//   dataSource.value.some(({ editing }) => editing === true),
// )
let disabled = computed(() => {
  return (
    !treeSelectedInfo.value ||
    (treeSelectedInfo.value.children || []).length > 0 ||
    dataSource.value.length === 0 ||
    // createing.value ||
    !!lockForInUse.value
  )
})
</script>
